﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using AspNetCs.Model;
using AspNetCs.SQLServerDAL;
using AspNetCs.DALFactory;
using AspNetCs.IDAL;

namespace AspNetCs.Bll
{
    public class AgentBLL
    {
        IAgent dal = Conn.CreateAgent();

        /// <summary>
        /// 代理商登录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AgentLogin(AgentModel model)
        {
            return dal.AgentLogin(model);
        }
        /// <summary>
        /// 根据DATAROW,返回代理商资料
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public AgentModel GetModel(DataRow dr)
        {
            return dal.GetModel(dr);
        }

        public AgentModel GetModel(string filter)
        {
            AgentModel Md = new AgentModel();
            DataTable dt = GetDataTable(filter);
            foreach (DataRow dr in dt.Rows)
            {
                Md = GetModel(dr);
            }
            return Md;
        }

        /// <summary>
        /// 根据ID,返回代理商资料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AgentModel GetModel(int id)
        {
            return dal.GetModel(id);
        }


        /// <summary>
        /// 当代理商登录以后,更新代理商最后登录资料
        /// </summary>
        /// <param name="id"></param>
        public void UpdateAgentLast(int id)
        {
            dal.UpdateAgentLast(id);
        }

        public DataTable GetDataTable(string filter)
        {
            return dal.GetDataTable(filter);
        }

        public int UpdateAgent(AgentModel model)
        {
            return dal.UpdateAgent(model);
        }

        public int AddAgent(AgentModel model)
        {
            return dal.AddAgent(model);
        }
    }
}
